package com.mgr.dao.impl;

import java.util.Date;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.mgr.dao.TransactionDao;
import com.mgr.model.Transactions;

@Repository
public class TransactionDaoImpl implements TransactionDao {

	@Autowired
	private SessionFactory session;

	@Override
	public void addtransaction(Transactions transaction) {
		session.getCurrentSession().save(transaction);
	}

	@Override
	public List<Transactions> getTransByTime(int accId, Date startDate,
			Date endDate) {
		String hql = "FROM Transactions A WHERE A.accId1 = :accId " +
				"AND (A.transDate BETWEEN :startDate AND :endDate)";
		Query query = session.getCurrentSession().createQuery(hql);
		query.setParameter("accId",accId);
		query.setParameter("startDate",startDate);
		query.setParameter("endDate",endDate);
		System.out.println(startDate);
		List<Transactions> results = query.list();
	
		return results;
	}

}
